package com.example.mydemo2;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

public class BusinessRecycleAdapter extends RecyclerView.Adapter<BusinessRecycleAdapter.BusinessViewHolder> {

    public List<BusinessItem> businessList;
    public void setData(List<BusinessItem> businessList){
        this.businessList = businessList;
    }

    @NonNull
    @Override
    public BusinessViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
      View view =  LayoutInflater.from(parent.getContext()).inflate(R.layout.item_list_business,parent,false);
        return new BusinessViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull BusinessViewHolder holder, int position) {
        BusinessItem businessItem = businessList.get(position);
        holder.businessImage.setImageResource(businessItem.getBusinessImage());
        holder.tvBusinessNick.setText(businessItem.getTvBusinessNick());
        holder.tvBusinessDistance.setText(businessItem.getTvBusinessDistance());
        holder.tvBusinessState.setText(businessItem.getTvBusinessState());

    }

    @Override
    public int getItemCount() {
        return businessList == null? 0 : businessList.size();
    }

    static class BusinessViewHolder extends RecyclerView.ViewHolder{


        ImageView businessImage;
        TextView tvBusinessNick;
        TextView tvBusinessDistance;
        Button tvBusinessState;
        public BusinessViewHolder(@NonNull View itemView) {
            super(itemView);
            businessImage = itemView.findViewById(R.id.business_image);
            tvBusinessNick = itemView.findViewById(R.id.tv_business_nick);
            tvBusinessDistance = itemView.findViewById(R.id.tv_business_distance);
            tvBusinessState = itemView.findViewById(R.id.tv_business_state);
        }
    }

}
